package com.firebird.app.kotlin.stock.trend.activity

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager.widget.ViewPager
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.firebird.app.kotlin.stock.trend.adapter.NewsFragmentAdapter
import com.firebird.app.kotlin.stock.trend.fragment.FragmentNavigatorA
import com.firebird.app.kotlin.stock.trend.fragment.FragmentNewsYw
import com.firebird.app.kotlin.stock.trend.view.FooterMenuView
import com.firebird.app.kotlin.stock.trend.R
import com.firebird.app.kotlin.stock.trend.view.NewsTabView
import java.util.*


/**
 * 资讯窗口界面
 * @author ljk
 * @date   2019年11月6日
 */
class NewsActivity : FragmentActivity(), OnPageChangeListener {
    private var tab_news: NewsTabView? = null
    private var viewPager: ViewPager? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        this.setContentView(R.layout.activity_news)
        //初始化底部菜单控件
        //val menu = findViewById<View>(R.id.footer_menu) as FooterMenuView
       // menu.setCurrentMenu(R.id.menu_news)
       // menu.setOnTouchListener(menu.MenuOnTouchListener())
        viewPager = findViewById<View>(R.id.vp_fragment) as ViewPager
        viewPager!!.adapter = NewsFragmentAdapter(supportFragmentManager, createFragments())
        viewPager!!.addOnPageChangeListener(this)
        //初始化animationTabWidget控件
        tab_news = findViewById<View>(R.id.zx_title) as NewsTabView
        tab_news!!.setOnClickListener(tab_news)
        tab_news!!.setViewPager(viewPager) //必须在viewPager空间实例化后设置
    }

    private fun createFragments(): ArrayList<Fragment> {
        val list: ArrayList<Fragment> = ArrayList<Fragment>()
        val yw = FragmentNewsYw()
        val f1 = FragmentNavigatorA(this)
        list.add(yw)
        list.add(f1)
        return list
    }

    override fun onPageScrollStateChanged(arg0: Int) {}
    override fun onPageScrolled(arg0: Int, arg1: Float, arg2: Int) {}
    override fun onPageSelected(position: Int) {
        if (tab_news != null) {
            tab_news!!.setCurrentTab(position)
        }
    }
}










